package org.eyeTopLight.utilities;


import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

import java.util.*;

public class SharedUtilities {

    private static final SharedUtilities instance = new SharedUtilities();

    private SharedUtilities(){}

    public static SharedUtilities getInstance(){
        return instance;
    }

    public Set<String> convertStringToSet(String itemArrayList){
        if(itemArrayList==null){
            return null;
        }
        Set<String> convertResult = new HashSet<>();
        String grantTypes[] = itemArrayList.split(",");
        for(int i =0 ;i<grantTypes.length;i++){
            convertResult.add(grantTypes[i]);
        }
        return convertResult;
    }

    public List<GrantedAuthority> convertStringToList(String itemArrayList){
        List<GrantedAuthority> authorities = new ArrayList<>();
        String roleArray[] = itemArrayList.split(",");
        for (String authority : roleArray){
            authorities.add(new SimpleGrantedAuthority(authority));
        }
        return authorities;
    }

}
